/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.memberView;
/**
 * 说明：
 */
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.ruipengkj.bean.TRole;
import com.ruipengkj.commons.base.query.PageView;
import com.ruipengkj.view.base.BasePanel;
import com.ruipengkj.view.statementView.StatementPermissions;
import com.ruipengkj.view.statementView.StatementRole;

public class PermissionsPanel extends BasePanel implements ListSelectionListener,Runnable{
	private static final long serialVersionUID = 1L;
	private StatementPermissions statementPurchaseOrder;// 翻页组件
	private StatementRole statementRole;
	private CardLayout right_layout;
	private CardLayout left_layout;
	private JPanel right_panel;
	private JPanel left_panel;
	private PageView<TRole> pageView;//翻页主键
	
	public PermissionsPanel() {
		this.setLayout(new BorderLayout());
		init();
	}
	
	private void init() {
		
		pageView=new PageView<TRole>();
		JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
//		jsp.setOpaque(false);
//		jsp.add(initLeft(), JSplitPane.TOP);
//		jsp.add(initRight(), JSplitPane.BOTTOM);
		
		JPanel right = initRight();
		JPanel left = initLeft();
		jsp = uiFactory.createJSplitPane(left, right, 0, 200,
				2, true);
		jsp.setBackground(new Color(247, 252, 255));
		this.add(jsp, BorderLayout.CENTER);
		// 排序
		//TableRowSorter<DataRoleModel> tableRowSorter = new TableRowSorter<DataRoleModel>(dataCommodityModel);
		//table.setRowSorter(tableRowSorter);
	}

	private JPanel initRight() {
		right_layout = new CardLayout();
		right_panel = new JPanel(right_layout);
		right_panel.setOpaque(false);
		
		statementPurchaseOrder = new StatementPermissions();
		
		right_panel.add(statementPurchaseOrder, "a");
		right_layout.show(right_panel, "a");
		SwingUtilities.invokeLater(statementPurchaseOrder);
		return right_panel;
	}

	private JPanel initLeft() {
		left_layout = new CardLayout();
		left_panel = new JPanel(left_layout);
		left_panel.setOpaque(false);
		statementRole = new StatementRole(statementPurchaseOrder);
		left_panel.add(statementRole, "a");
		left_layout.show(left_panel, "a");
		statementRole.setRoleSelectChangeListener(this);
		statementRole.setLeftListener(this);
		SwingUtilities.invokeLater(statementRole);
		return left_panel;
		
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getClickCount() == 1) {
				String ID=statementRole.getID();
				statementPurchaseOrder.queryRights(ID);
				right_panel.add(statementPurchaseOrder, "a");
				right_layout.show(right_panel, "a");
				SwingUtilities.invokeLater(statementPurchaseOrder);

		}
	}

	@Override
	public void valueChanged(ListSelectionEvent e) {
		if(e.getValueIsAdjusting())
			return;
		String ID=statementRole.getID();
		statementPurchaseOrder.queryRights(ID);
		right_panel.add(statementPurchaseOrder, "a");
		right_layout.show(right_panel, "a");
		SwingUtilities.invokeLater(statementPurchaseOrder);
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}
}